package com.hziee.graduate.ticket.dao;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hziee.graduate.ticket.vo.TicketVO;
import org.apache.ibatis.annotations.Param;
import com.hziee.graduate.ticket.entity.Tickets;
import org.apache.ibatis.annotations.Select;


public interface TicketsDao extends BaseMapper<Tickets> {

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Tickets> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Tickets> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Tickets> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Tickets> entities);

    @Select("select t.ticket_id as ticketId, t.order_id as orderId, t.pay_status as payStatus, t.check_status as checkStatus, t.schedule_id as scheduleId, " +
            "s.cinema_id as cinemaId, s.start, s.end, s.date,\n" +
            "c.cinema_name as cinemaName,c.cinema_address as cinemaAddress,\n" +
            "m.movie_name as movieName,m.movie_price as moviePrice,m.movie_id as movieId,\n" +
            "r.room_name as roomName\n" +
            "from t_tickets t\n" +
            "join t_schedule s on t.schedule_id = s.schedule_id\n" +
            "join t_cinema c on s.cinema_id = c.cinema_id\n" +
            "join t_movie m on m.movie_id = t.movie_id\n" +
            "join t_room r on r.room_id = t.room_id\n" +
            "where t.ticket_id = #{ticketId}")
    TicketVO getTicketVO(@Param("ticketId") Long ticketId);

    @Select("select count(*) from t_tickets t\n" +
            "join t_movie m on t.movie_id = m.movie_id\n" +
            "join t_schedule s on t.schedule_id = s.schedule_id\n" +
            "where m.movie_name = #{movieName} and s.date = #{date}")
    Integer getTicketByMovieAndDate(@Param("movieName") String movieName, @Param("date") String date);
}

